package com.imc.core.config.druid;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by tanweiping on 2018/7/24.
 */
/*
* 类描述：数据库连接池的yml对应
* 开发者：tanweiping
* 创建日期：2018/8/7 10:00
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Component
@ConfigurationProperties(prefix = "druid")
public class DruidProperty {
    /*
    # 黑名单
    dency:
      - 192.168.1.1
    # 白名单
    allow:
      - 127.0.0.1
    login:
      username: admin
      password: 123456
     */
    private List<String> dency;
    private List<String> allow;

    private Login login;

    /*
    * tanweiping  2018/8/7 10:18
    * 方法描述：获取白名单
    */
    public String getAllowStr(){
        if (allow==null||allow.isEmpty()) return "";
        return getAllow().stream().reduce((a,b)->a.concat(",").concat(b)).get();
    }

    /*
    * tanweiping  2018/8/7 10:19
    * 方法描述：获取黑名单
    */
    public String getDencyStr(){
        if (dency==null||dency.isEmpty()) return "";
        return getDency().stream().reduce((a,b)->a.concat(",").concat(b)).get();
    }


    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Login{
        private String username;
        private String password;
    }

}
